Desk Invaders is a version of the classic arcade game ╥Space Invaders╙, implemented as a DA! You can shoot away at those little critters whenever the stress and strain of using your Mac gets too much, whatever application you may be running.
Desk Invaders is free, and you may give it away to your friends and colleagues as you please, as long as the game is copied unmodified, and this document accompanies it.
I wrote Desk Invaders as an exercise in Mac programming, and to be a cute piece of software. I hope I succeeded. If you enjoy it, I would appreciate a postcard or note from your home town.
Now the bad news. Desk Invaders can╒t be run on anything other than a Macintosh II family member (or an LC) with 256 colours or gray levels set for it╒s main monitor. Sorry to be elitist, Mac Plus and SE users, but let╒s face it, a black and white shoot-em-up? A trifle dull. However I might do a b&w version if there is a demand. The 8 bit caveat is due to the fact that the pixel images used in the game are 8 bit, and copying to a screen of another depth reduces game speed to glacial proportions, as well as ruining the dithered shading effects.
Talking of game speed, because this is a DA, it relies on co-operation from the host application to call it often enough to keep everything moving smoothly. Normally, this is OK, but some applications are a bit naughty in this respect, like MacWrite II under MultiFinder, and most notably Hypercard. What is Hypercard doing all the time? It╒s a mystery.
One other word of warning. Because this DA needs a little more RAM than most, if you are running under MultiFinder, I don╒t advise opening the DA in the application layer (by holding down the option key when the DA is chosen), especially in the Finder╒s layer. Although I try to recover gracefully from low memory, this is not foolproof. Let DA Handler handle the DA under MultiFinder. That is it╒s job, after all.
The DA is (I hope) fully self explanatory. Use the Desk Invaders menu to show Help and ╥About╙ messages. The ╥Bunkers╙ option selects whether defensive bunkers are enabled or not.
Bonuses are awarded for shooting the Motherships. The faster they go, the more points you get if you hit one. You also get a 50 point per second bonus for completing a level inside 45 seconds.
Motherships occaisionally drop Smart Bombs. These home in on your position, but can be shot down or dodged. If one hits a bunker, the bunker is destroyed completely.
As you go up the levels, the Invaders get tougher and more determined to kill you.
Have Fun!
This program is dedicated to the Apple programmer who wrote the CopyBits toolbox call, without which this program would just sit there doing nothing. Was it Bill Atkinson?
Techie Stuff.
I am often intrigued (being a techie programmer type) how programmers achieve certain effects in games, etc. But, they never volunteer the information. So here is a brief description of how this program does what it does, for those of you who give a damn.
DA╒s receive events prefiltered by the application sitting underneath them, and therefore event handling is actually easier in a DA than in an application. One type of event a DA receives is call ╘AccCursor╒ which is called once each time round the host application╒s main loop, as long as the DA window is in front. In Desk Invaders, this call is used to perform almost all of the game action. A DA can also request calls on a periodic basis, and Desk Invaders uses a 1 second ╘AccRun╒ event to handle the bonus timer. Other events, such as MouseDown and Key events, are used to fire off your bullet.
To keep everything moving smoothly, with no nasty jerks in the action when different things happen, each entity on screen has a timer associated with it, which controls it╒s rate. For example, the routine to move the invaders is called every AccCursor call, but if it╒s own timer has not reached the appointed time (as determined by TickCount), the routine returns without performing any movement, and the program calls the next routine, to move the base or bullets, for example. This method means that action continues at the same rate regardless of what the CPU clock speed is.
Desk Invaders is unusual for a Mac arcade game in that it relies totally on QuickDraw, and does not access the video RAM directly. This approach is inherently slower, so certain measures have to be taken to pre-arrange the graphics to keep the speed reasonable. The graphics for Desk Invaders are held in it╒s resource fork as PICT resources, which makes them easy to edit. But drawing pictures is slow, so Desk Invaders creates a set of offscreen GrafPorts when it is opened, into which the PICT╒s are drawn. The pictures are then released, and take no further part in the action. The call CopyBits (or it╒s close cousin, CopyMask) is used to transfer blocks of pixels from the offscreen ports to the DA window. CopyBits is fast, as long as the source and destination ports have the same pixel depth, and use the same set of colours. (Desk Invaders uses the standard system palette everywhere.) This explains the problem of non-8-bit screens.
Each graphic element is drawn in two stages; first the old position is used to replot the background, then the new position is used to plot the element. Various tricks and manipulations are done to eliminate flicker, usually involving the use of a mask for the element, also created from a PICT using the offscreen method. Negative masks are sometimes used when filling in background, and this is generated from the positive mask in a seperate offscreen port by inverting. Sometimes, regions are used as a mask, as in the case of the bunkers and the invaders themselves.
Offscreen ports require a fair amount of RAM for their images. Desk Invaders requires a total of about 150K of heap space in operation.
Text is drawn using DrawString or TextBox. Some graphics, which are not time critical, are drawn directly from the PICT resource using DrawPicture. All in all, this should run on most Macs without difficulty, as it follows the rules all the way!
Desk Invaders is critically dependant on it╒s resources. In particular, the graphic elements PICTs and the ╘nrct╒ resource which defines the element areas for plotting, should never be edited. You have been warned, adventurous types!
Desk Invaders was written in THINK C version 4.0, and as such contains portions of code copyright Symantec corp. It took about 4 days to write, 4 days I should have spent doing something much more constructive (although probably less creative).